package com.isunland.managesystem.ui;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.MessageContact;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;

public class AppointerDialogFragment extends BaseNetworkDialogFragment {

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    try {

      Type listType = new TypeToken<ArrayList<MessageContact>>() {
      }.getType();

      ArrayList<MessageContact> messageDialogs = new Gson().fromJson(arg0, listType);
      if (messageDialogs == null || messageDialogs.size() == 0) {

        return null;
      }
      //委派人必须有个清空的选项,在所有人上面加一个"无"
      list.add(new CustomerDialog("无", "clear"));
      for (int i = 0; i < messageDialogs.size(); i++) {
        list.add(
            new CustomerDialog(messageDialogs.get(i).getName(), messageDialogs.get(i).getJobNo()));
      }
      return list;
    } catch (Exception e) {

    }

    return list;
  }

  @Override public String getUrl() {

    return ApiConst.URL_QUERY_MEMBER;
  }

  @Override public HashMap<String, String> getparameters() {

    HashMap<String, String> params = new HashMap<String, String>();
    params.put("type", "user");
    String memberCode = CurrentUser.newInstance(getActivity()).getMemberCode();
    params.put("orgCode", memberCode);
    return params;
  }
}
